#include<bits/stdc++.h>
using namespace std;
const int N = 200050;
int T;
int n;
int a[N],c[N];
bool col[N];
int maxn = 0;
bool fin(int loc)
{
    bool cnt = false;
    for(int i=1;i<=loc;i++)
    {
        if(col[i] == true)
        {
            if(a[i] == a[loc]) cnt = true;
            else cnt = false;
        }
    }
    return cnt;
}
void dfs(int loc,node a)
{
    if(loc == n+1)
    {
        for(int i=1;i<=n;i++)
        {
            sum+=c[i];
        }
        break;
    }
    col[loc] = true;//dangqian ranhong;
    if(fin(loc)) c[loc] = a[loc];
    dfs(loc+1,a);
    c[loc] = 0;
    col[loc] = false;
    dfs(loc+1,a);

}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--)
    {
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        maxn = 0;
        dfs(1,a,0);
        cout<<maxn;

    }
    return 0;
}
